package la.common.xml;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class XPathHelper {
	
	private XPathExpression pathExpression;

	public XPathHelper(XPathExpression pathExpression) {
		super();
		this.pathExpression = pathExpression;
	}

	public void sureSetElementTextContent(Node node, String textContent) {
		try {
			Element targetElement = (Element) pathExpression.evaluate(node, XPathConstants.NODE);
			targetElement.setTextContent( textContent );
		} catch (XPathExpressionException e) {
			throw new RuntimeException( e );
		}
	}
}
